{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import geopandas as gpd\n",
    "import rasterio\n",
    "import xarray as xr\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "from geopandas import GeoSeries\n",
    "import os\n",
    "import h5py\n",
    "from shapely.geometry import Point,Polygon\n",
    "import glob\n",
    "from rasterio import features\n",
    "from topolib import gda_lib\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "ATL06_list = glob.glob('/home/jovyan/data/*.h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "e=True\n",
    "\n",
    "a=0\n",
    "valid = []\n",
    "for i in range(len(ATL06_list)):\n",
    "    try:\n",
    "        xr.open_mfdataset(ATL06_list[i], group='/gt1r/land_ice_segments')\n",
    "        valid.append(True)\n",
    "        #print(\"Hello\")\n",
    "    except:\n",
    "        valid.append(False)\n",
    "        continue "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from itertools import compress"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "valid_fn = list(compress(ATL06_list,valid))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#valid_fn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "temp=xr.open_mfdataset(valid_fn, group='/gt1r/land_ice_segments')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<xarray.Dataset>\n",
       "Dimensions:                (delta_time: 11678395)\n",
       "Coordinates:\n",
       "  * delta_time             (delta_time) datetime64[ns] 2018-10-18T20:56:40.365586956 ... 2018-11-01T21:18:41.360825216\n",
       "    latitude               (delta_time) float64 dask.array<shape=(11678395,), chunksize=(37112,)>\n",
       "    longitude              (delta_time) float64 dask.array<shape=(11678395,), chunksize=(37112,)>\n",
       "Data variables:\n",
       "    atl06_quality_summary  (delta_time) int8 dask.array<shape=(11678395,), chunksize=(37112,)>\n",
       "    h_li                   (delta_time) float32 dask.array<shape=(11678395,), chunksize=(37112,)>\n",
       "    h_li_sigma             (delta_time) float32 dask.array<shape=(11678395,), chunksize=(37112,)>\n",
       "    segment_id             (delta_time) float64 dask.array<shape=(11678395,), chunksize=(37112,)>\n",
       "    sigma_geo_h            (delta_time) float32 dask.array<shape=(11678395,), chunksize=(37112,)>\n",
       "Attributes:\n",
       "    Description:  The land_ice_height group contains the primary set of deriv...\n",
       "    data_rate:    Data within this group are sparse.  Data values are provide..."
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "icesatt=temp.to_dataframe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'function' object has no attribute 'h_li'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-24-4addaf51a3a6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0micesatt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mh_li\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m: 'function' object has no attribute 'h_li'"
     ]
    }
   ],
   "source": [
    "icesatt.h_li"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
